1877D - Effects of Anti Pimples - CodeForces Solution


combinatorics number theory sortings

Please click on ads to support us..

C++ Code:

#include "bits/stdc++.h"
using namespace std;
#define int               long long
#define ll               long long
#define uniq(v)           (v).erase(unique(all(v)),(v).end())

//const long long INF=1e18;
//const int32_t M=1e9+7;
const int32_t MM=998244353;
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
void solve()
{
	int n;
	cin>>n;
	vector<int> nums(n);
	for(int i=0;i<n;i++)
	{
		cin>>nums[i];
	}
	vector<int> v(n);
	for(int i=0;i<n;i++)
	{
		int ma=INT_MIN;
		for(int j=i;j<n;j=j+(i+1))
		{
			ma=max(ma,nums[j]);
		}
		v[i]=ma;

	}


	

	// for(int i=0;i<n;i++)
	// {
	// 	cout<<v[i]<<" ";
	// }
	int ans=0;
	sort(v.begin(),v.end());

	for(int i=0;i<n;i++)
	{
		int t=expo(2,i,MM);
		int g=mod_mul(v[i],t,MM);

		int k=mod_add(g,ans,MM);
		//cout<<t<<" "<<g<<" "<<k<<endl;
		ans=k;
	}
	cout<<ans<<endl;


}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SIEVE
		sieve();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Comments

Submit
0 Comments
More Questions

189A - Cut Ribbon
1182A - Filling Shapes
82A - Double Cola
45A - Codecraft III
1242A - Tile Painting
1663E - Are You Safe
1663D - Is it rated - 3
1311A - Add Odd or Subtract Even
977F - Consecutive Subsequence
939A - Love Triangle
755A - PolandBall and Hypothesis
760B - Frodo and pillows
1006A - Adjacent Replacements
1195C - Basketball Exercise
1206A - Choose Two Numbers
1438B - Valerii Against Everyone
822A - I'm bored with life
9A - Die Roll
1430B - Barrels
279B - Books
1374B - Multiply by 2 divide by 6
1093B - Letters Rearranging
1213C - Book Reading
1468C - Berpizza
1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel
1647D - Madoka and the Best School in Russia
1208A - XORinacci